//
//  UIButton+block.m
//  YiYueStore
//
//  Created by zhouzhouzhou on 2018/9/27.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "UIButton+ZYHblock.h"

@implementation UIButton (ZYHblock)


-(void)changeButtonImgTopTextBottom{
    //使图片和文字水平居中显示
    self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    
    //    文字距离上边框的距离增加imageView的高度，距离左边框减少imageView的宽度，距离下边框和右边框距离不变
    [self setTitleEdgeInsets:UIEdgeInsetsMake(self.imageView.frame.size.height + 20 ,-self.imageView.frame.size.width, 0.0,0.0)];
    
    //图片距离右边框距离减少图片的宽度，其它不边
    [self setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0,10, -self.titleLabel.bounds.size.width)];
    //    self.titleEdgeInsets = UIEdgeInsetsMake(0, -self.imageView.bounds.size.width+2, 0, self.imageView.bounds.size.width);
    //    // button图片的偏移量
    //    self.imageEdgeInsets = UIEdgeInsetsMake(0, self.titleLabel.bounds.size.width, 0, -self.titleLabel.bounds.size.width);
    
}


-(void)setDidSelectBtn:(void(^)(UIButton*sender))didSelectBtn{
    
           objc_setAssociatedObject(self,@selector(didSelectBtn), didSelectBtn,OBJC_ASSOCIATION_COPY_NONATOMIC);
    
           [self addTarget: self action:@selector(click:)forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)click:(UIButton*)btn{
    if(self.didSelectBtn) {
        self.didSelectBtn(btn);
    }
}

-(void(^)(UIButton*))didSelectBtn{
    
     return objc_getAssociatedObject(self,@selector(didSelectBtn));
    
}

@end
